﻿using BCCommon.Enums;
using BCData.WeChatComponent.WeChatMessageRecord;
using BCEntity.WeChatComponent.WeChatMessageRecord;
using System;
using System.Collections.Generic;
using System.Text;
using WeChatSDK.WeChatDto.Conversation.ReceivingMessage;

namespace BCService.WeChatComponent.WeChatHandleService.ShortVideoMessageService
{
    /// <summary>
    /// 微信视频、小视频消息处理
    /// </summary>
    public class ShortVideoMessageService : IWeChatMessageHandle
    {
        private readonly IWeChatMessageRecordData weChatMessageRecordData;

        public ShortVideoMessageService(IWeChatMessageRecordData weChatMessageRecordData)
        {
            this.weChatMessageRecordData = weChatMessageRecordData;
        }

        public string HandleMessage(ReceivingMessageDto message)
        {
            ShortVideoMessageDto shortVideoMessageDto = (ShortVideoMessageDto)message;
            WeChatMessageRecordEntity weChatMessageRecordEntity = this.RecordReceivingMessage(shortVideoMessageDto);
            string response = "success";
            return response;
        }

        private WeChatMessageRecordEntity RecordReceivingMessage(ShortVideoMessageDto shortVideoMessageDto)
        {
            WeChatMessageRecordEntity entity = new WeChatMessageRecordEntity()
            {
                ToUserName = shortVideoMessageDto.ToUserName,
                FromUserName = shortVideoMessageDto.FromUserName,
                MessageType = (WeChatMessageType)Enum.Parse(typeof(WeChatMessageType),shortVideoMessageDto.MsgType.Substring(0,1).ToUpper()+shortVideoMessageDto.MsgType.Substring(1)),
                MessageId = shortVideoMessageDto.MsgId,
                MediaId = shortVideoMessageDto.MediaId,
                ThumbMediaId = shortVideoMessageDto.ThumbMediaId,
                IsReply = false
            };
            return this.weChatMessageRecordData.Add(entity);
        }
    }
}
